package visitor;

import java.util.Iterator;
import compositeExpression.Cond;
import compositeExpression.Expr;
import compositeExpression.Expression;
import compositeExpression.Term;
import compositeExpression.Termb;
import compositeExpression.Termp;
import compositeExpression_Fact.FactExpr;
import compositeExpression_Fact.FactId;
import compositeExpression_Fact.FactNum;
import compositeExpression_Factb.FactbCond;
import compositeExpression_Factb.FactbNot;
import compositeExpression_Factb_FactbExpr.RelopEq;
import compositeExpression_Factb_FactbExpr.RelopGe;
import compositeExpression_Factb_FactbExpr.RelopGt;
import compositeExpression_Factb_FactbExpr.RelopLe;
import compositeExpression_Factb_FactbExpr.RelopLt;
import compositeExpression_Factb_FactbExpr.RelopNeq;


public class SimmetricVisitor implements Visitor {
	
	 private StringBuilder sb;

	    public SimmetricVisitor() {

	        sb = new StringBuilder("VISITOR SELEZIONATO: Simmetrico \n");

	    }

	    @Override
	    public void visit(Cond cond) {

	        if (cond.getState().size() == 1) {

	            cond.getState().get(0).accept(this);
	            sb.append(" Cond ");
	        } else {

	            Iterator<Expression> it = cond.getState().iterator();

	            it.next().accept(this);
	            while (it.hasNext()) {

	                sb.append(" Cond ");
	                it.next().accept(this);
	            }
	        }
	    }

	    @Override
	    public void visit(Termb termb) {

	        if (termb.getState().size() == 1) {

	            termb.getState().get(0).accept(this);
	            sb.append(" Termb ");
	        } else {

	            Iterator<Expression> it = termb.getState().iterator();

	            it.next().accept(this);
	            while (it.hasNext()) {

	                sb.append(" Termb ");
	                it.next().accept(this);
	            }
	        }
	    }

	    @Override
	    public void visit(FactbCond factbCond) {

	        factbCond.getState().accept(this);
	        sb.append(" FactCond ");
	    }

	    @Override
	    public void visit(FactbNot factbNot) {

	        factbNot.getState().accept(this);
	        sb.append(" FactNot ");
	    }

	    @Override
	    public void visit(RelopEq relopEq) {

	        relopEq.getleft().accept(this);

	        sb.append(" RelopEq ");

	        relopEq.getRight().accept(this);
	    }

	    @Override
	    public void visit(RelopGe relopGe) {

	        relopGe.getleft().accept(this);

	        sb.append(" RelopGe ");

	        relopGe.getRight().accept(this);
	    }

	    @Override
	    public void visit(RelopGt relopGt) {

	        relopGt.getleft().accept(this);

	        sb.append(" RelopGt ");

	        relopGt.getRight().accept(this);
	    }

	    @Override
	    public void visit(RelopLe relopLe) {

	        relopLe.getleft().accept(this);

	        sb.append(" RelopLe ");

	        relopLe.getRight().accept(this);
	    }

	    @Override
	    public void visit(RelopLt relopLt) {

	        relopLt.getleft().accept(this);

	        sb.append(" RelopLt ");

	        relopLt.getRight().accept(this);
	    }

	    @Override
	    public void visit(RelopNeq relopNeq) {

	        relopNeq.getleft().accept(this);

	        sb.append(" RelopNeq ");

	        relopNeq.getRight().accept(this);
	    }

	    @Override
	    public void visit(Expr expr) {

	        if (expr.getState().size() == 1) {

	            expr.getState().get(0).accept(this);
	            sb.append(" Expr ");
	        } else {

	            Iterator<Expression> it = expr.getState().iterator();

	            it.next().accept(this);
	            while (it.hasNext()) {

	                sb.append(" Expr ");
	                it.next().accept(this);
	            }
	        }
	    }

	    @Override
	    public void visit(Termp termp) {

	        if (termp.getState().size() == 1) {

	            termp.getState().get(0).accept(this);
	            sb.append(" Termp ");
	        } else {

	            Iterator<Expression> it = termp.getState().iterator();

	            it.next().accept(this);
	            while (it.hasNext()) {

	                sb.append(" Termp ");
	                it.next().accept(this);
	            }
	        }
	    }

	    @Override
	    public void visit(Term term) {

	        if (term.getState().size() == 1) {

	            term.getState().get(0).accept(this);
	            sb.append(" Term ");
	        } else {

	            Iterator<Expression> tp = term.getState().iterator();

	            tp.next().accept(this);

	            while (tp.hasNext()) {

	                sb.append(" Term ");

	                tp.next().accept(this);
	            }
	        }
	    }

	    @Override
	    public void visit(FactExpr factExpr) {

	        factExpr.getState().accept(this);
	    }

	    @Override
	    public void visit(FactId factId) {

	        sb.append(" FactId ");
	    }

	    @Override
	    public void visit(FactNum factNum) {

	        sb.append(" FactNum ");
	    }

	    @Override
	    public String toString() {

	        return sb.toString();
	    }


}
